<template>
  <div class="app-container">

      <div style="height: 30px;margin:5px;">
        <span>场站名称：{{stationName}}</span>
      </div>

      <el-table  :data="ledgers" :row-key="getRowKeys" :indent="40" :expand-row-keys="expands" height="800px"   @expand-change="expandSelect"  :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
        <el-table-column label="台账名称" align="left" prop="ledgerName" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope" >
            <el-button v-if="scope.row.isShow==='1'"
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleLedgerView(scope.row)"
              v-hasPermi="['weight:station:query']"
            >详细</el-button>
          </template>
        </el-table-column>
      </el-table>
  </div>
</template>

<script>
  import { getToken } from "@/utils/auth";

  export default {
    name: "Station",
    data() {
      return {
        stationId: undefined,
        stationName: undefined,
        // 台账信息表格数据
        ledgers: [],
        expands: [],
        getRowKeys (row) {
          return row.id
        },
      };
    },
    created() {
      console.log(this.$route)
      console.log(this.$route.params.stationName)


      const stationId = this.$route.params && this.$route.params.stationId;
      this.stationId=stationId;
      const stationName = this.$route.params && this.$route.params.stationName;
      this.stationName=stationName;
      const ledgerList3 = [
        {"id":301,"ledgerName":"消防设备台账","stationId":stationId,"name":"equipmentView","stationName":stationName,"isShow":"1"},
        {"id":302,"ledgerName":"消防设施台账","stationId":stationId,"name":"facilitiesView","stationName":stationName,"isShow":"1"}
      ];
      const ledgerList4 = [
        {"id":401,"ledgerName":"安全生产领导小组会议记录","stationId":stationId,"name":"meetingView","stationName":stationName,"isShow":"1"},
        {"id":402,"ledgerName":"安全教育活动记录","stationId":stationId,"name":"educationView","stationName":stationName,"isShow":"1"}
      ];
      const ledgerList1 = [
         {"id":100,"ledgerName":"场站管理人员信息","stationId":stationId,"name":"managementView","stationName":stationName,"isShow":"1"},
         // {"id":101,"ledgerName":"进驻经营业户登记台账","stationId":stationId,"name":"businessView","stationName":stationName,"isShow":"1"},
         // {"id":102,"ledgerName":"消防设施设备管理台账","stationId":stationId,"name":"manageView","stationName":stationName,"isShow":"1"},
         {"id":103,"ledgerName":"进驻经营业户信息","stationId":stationId,"name":"accountView","stationName":stationName,"isShow":"1"},
         {"id":104,"ledgerName":"经营户人员信息","stationId":stationId,"name":"businessWorkerView","stationName":stationName,"isShow":"1"},
         {"id":105,"ledgerName":"叉车信息","stationId":stationId,"name":"forkliftView","stationName":stationName,"isShow":"1"},
         {"id":106,"ledgerName":"消防设备信息","stationId":stationId,"name":"equipmentView","stationName":stationName,"isShow":"1"},
         // {"id":106,"ledgerName":"消防设备设施台账","isShow":"0",children: ledgerList3}
        /*{"ledgerName":"治超管理台账","stationId":stationId,"name":"registrationView"},*/
        /*{"ledgerName":"车辆出场检查台账","stationId":stationId,"name":"checkView"},*/
      ];
      const ledgerList2 = [
         {"id":201,"ledgerName":"安全生产事故隐患排查治理","stationId":stationId,"name":"inspectionView","stationName":stationName,"isShow":"1"},
         // {"id":202,"ledgerName":"叉车检查项目","stationId":stationId,"name":"inspectView","stationName":stationName,"isShow":"1"},
         {"id":203,"ledgerName":"安全生产教育","isShow":"0",children: ledgerList4},
         {"id":204,"ledgerName":"专项活动","stationId":stationId,"name":"activityView","stationName":stationName,"isShow":"1"}
         // {"id":204,"ledgerName":"隐患自查自纠表","stationId":stationId,"name":"dangerView","stationName":stationName,"isShow":"1"}
       ];
      this.ledgers = [
        {"id":1,"ledgerName":"台账管理","isShow":"0",children: ledgerList1},
        {"id":2,"ledgerName":"安全生产管理","isShow":"0",children: ledgerList2}
      ];
    },
    mounted() {
      this.$nextTick(()=>{
        this.$set(this.$route.meta,"title",this.$route.params.stationName)
        // this.$route.meta.title= this.$route.params &&this.$route.params.stationName
      })
    },

    methods: {
      /** 台账信息 **/
      handleLedgerView(row){
        // this.$router.push({name: row.name, query: {stationId: row.stationId}})
        this.$router.push({name: row.name, params: {stationId: row.stationId , stationName: row.stationName}})
      },
      // 折叠面板每次只能展开一行
      expandSelect (row, expanded) {
        if (expanded) {
          this.expands = []
          if (row) {
            this.expands.push(row.id)
            console.log(this.expands)
          }
        } else {
          this.expands = []
          console.log(this.expands)
        }
      },
    }
  };
</script>


